package com.zd.lib.demo;

import android.util.Log;

import com.google.gson.Gson;
import com.zd.lib.http.response.BaseEntity;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Protocol;
import okhttp3.Response;
import okhttp3.ResponseBody;



/**
 * Created by zoudong on 2017/2/4.
 */

public class TestInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Gson gson = new Gson();
//        BaseEntity<List<ListEntity>> listBaseEntity = new BaseEntity<>();
//        ArrayList<ListEntity> list = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            list.add(new ListEntity(i, "item---" + i));
//        }
        BaseEntity<ListEntity> listBaseEntity = new BaseEntity<>();
        ListEntity listEntity = new ListEntity(10, "item---" + 10);
//        listEntity.strs = new ArrayList<>();
        listBaseEntity.setCode(0);
        listBaseEntity.setMsg("Test");
        listBaseEntity.setData(listEntity);
        String data = gson.toJson(listBaseEntity);
//        data = "{\"code\":0,\"data\":{},\"msg\":\"Test\"}";
        data = "{\"code\":0,\"data\":[{\"item\":10,\"str\":\"item---10\",\"strs\":[]}],\"msg\":\"Test\"}";
        Log.e("zoudong", "data"+data);
       return new Response.Builder()
                .request(chain.request())
                .protocol(Protocol.HTTP_1_1)
                .code(200)
                .body(ResponseBody.create(
                        chain.request().body().contentType(),
                        data )).build();
    }
}
